package ext;

/**
 * 单词反转
 */
public class Transform {
    public String trans(String s, int n) {

        String res = "";
        String word = "";
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c != ' ') {
                if (Character.isLowerCase(c))
                    word += Character.toUpperCase(c);
                else
                    word += Character.toLowerCase(c);
            } else {
                res = word + " " + res;
                word = "";
            }
        }
        res = word + " " + res;
        return res.substring(0, n);
    }

    public static void main(String[] args) {
        String str = "This is null";
        Transform transform = new Transform();
        System.out.println(transform.trans(str, str.length()));
    }
}
